package com.doform.android.xianggucheng.widget;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.doform.android.xianggucheng.R;

/**
 * Created by Administrator on 2017/5/16.
 */

public class TitleBar extends RelativeLayout {

    protected RelativeLayout leftLayout;
    protected ImageView leftImage;
    protected RelativeLayout rightLayout;
    protected ImageView rightImage;
    protected TextView titleView;
    protected TextView tv_right;
    protected RelativeLayout titleLayout;
    private RelativeLayout rl_back;
    private TextView tvTitle;
    private RelativeLayout rl;

    public TitleBar(Context context, AttributeSet attrs, int defStyle) {
        this(context, attrs);
    }

    public TitleBar(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context, attrs);
    }

    public TitleBar(Context context) {
        super(context);
        init(context, null);
    }

    private void init(Context context, AttributeSet attrs) {
        LayoutInflater.from(context).inflate(R.layout.title_layout, this);
        rl_back = (RelativeLayout) findViewById(R.id.rl_back);
        tvTitle = (TextView) findViewById(R.id.tv);
        tv_right = (TextView) findViewById(R.id.tv_right);
        rl = (RelativeLayout) findViewById(R.id.rl);
    }

    public void setBackgroundColor(Drawable color) {
        rl.setBackground(color);
    }

    public void setBackListener(OnClickListener onClickListener) {
        rl_back.setOnClickListener(onClickListener);
    }

    public void setRightText(String text) {
        tv_right.setText(text);
    }

    public void setRightListener(OnClickListener onClickListener) {
        tv_right.setOnClickListener(onClickListener);
    }

    public void setTextTitle(String title) {
        tvTitle.setText(title);
    }

    public void setBackGone() {
        rl_back.setVisibility(GONE);
    }

    public void setTextColor(int color) {
        tvTitle.setTextColor(color);
    }
}
